<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <title>
      Pomelo
    </title>
    <meta http-equiv="content-type" content="text/html;charset=utf-8" />
    <meta http-equiv="content-style-type" content="text/css" />
    <meta http-equiv="content-scripte-type" content="text/javascript" />
    <meta name="author" content="netease" />
    <meta name="version" content="1.0" />
    <meta name="keywords" content="pomelo" />
    <link type="text/css" rel="stylesheet" href="css/base.css" />
    <script src="js/lib/build/build.js" type="text/javascript"></script>
    <script type="text/javascript">
      require('boot');
    </script> 
    <script type="text/javascript">
      var pomelo = window.pomelo;
      var host = "127.0.0.1"        //
      // host = "120.55.61.144"
      var port = "3910";
      function show() {
          pomelo.request("connector.entryHandler.getNotify",null, function(data) {
              console.log(data)
          });
      }
      pomelo.on("onMessage",function(data) {
        console.log("onMessage")
        console.log(data)
      })
      pomelo.on("onNotify",function(data) {
        console.log("onNotify")
        console.log(data)
      })
      pomelo.on("disconnect",function(data) {
        // body...
        console.log("disconnect")
      })
      pomelo.on("close",function(data) {
        console.log("close")
      })
      pomelo.on("heartbeat timeout",function(data) {
        // body...
        console.log("heartbeat timeout")
      })
      pomelo.on("io-error",function(data) {
        // body...
        console.log("io-error")
        console.log(data)
      })

      //登录
      var vlogin = function(uid) {
        queryEntry(uid,function(host, port) {
          pomelo.init({
            host: host,
            port: port,
            log: true
          }, function() {
            var route = "connector.entryHandler.visitorEnter";
            pomelo.request(route,{"uid" : uid,inviter : 10001}, function(data) {
              console.log("!!!!!")
              console.log(data)
              if(data.error) {
                console.log(data)
                return;
              }
            });
          });
        });
      }
      var sendData = function(code,params) {
          pomelo.request("connector.entryHandler.sendData", {"code" : code,"params" : params || {}}, function(data) {
              console.log(data)
            }
          );
      }
      //申请验证码
      var sendCaptcha = function(phone) {
          pomelo.request("connector.identity.sendCaptcha", {"phone" : phone}, function(data) {
              console.log("flag is : "+data.flag)
            }
          );
      }
      //注册账号
      var register = function(phone,password,code,referrer) {
          pomelo.request("connector.identity.register", {"phone" : phone,"password" : password,"code" : code,
            "referrer" : referrer}, function(data) {
              console.log(data)
            }
          );
      }
      //手机登录
      var phoneLogin = function(phone,password) {
        queryEntry("",function(host, port) {
          pomelo.init({
            host: host,
            port: port,
            log: true
          }, function() {
            pomelo.request("connector.entryHandler.phoneLogin", {"phone" : phone,"password" : password}, function(data) {
                console.log(data)
              }
            );
          });
        });
      }
      //修改昵称
      var changeNickname = function(nickname) {
          pomelo.request("connector.identity.changeNickname", {"nickname" : nickname}, function(data) {
              console.log(data)
            }
          );
      }
      //修改头像
      var changeHeadType = function(headType) {
          pomelo.request("connector.identity.changeHeadType", {"headType" : headType}, function(data) {
              console.log(data)
            }
          );
      }
      
      //修改密码
      var changePassword = function(phone,password,code) {
          pomelo.request("connector.identity.changePassword", {"phone" : phone,"password" : password,"code" : code}, function(data) {
              console.log(data)
            }
          );
      }

      //创建新游戏   wantRole 代表哪个椅子号的玩家要哪个身份
      var newRoom = function() {
          sendData("newRoom",{gameType : "hqlMachine"})
      }
      //加入大厅房间
      var joinLobbyRoom = function(gameType,level,table) {
        sendData("joinLobbyRoom",{gameType : gameType || "hqlMachine",level : level || "low",table : table || 1})
      }
      //获取大厅房间数据
      var getLobbyInfo = function() {
        sendData("getLobbyInfo",{gameType : "hqlMachine",level : "free"})
      }
      //锁定机器
      var lockingMachine = function(type) {
        sendData("lockingMachine",{type: type})
      }
      //准备
      var ready = function() {
          sendData("ready")
      }
      //退出房间
      var userQuit = function() {
          sendData("userQuit")
      }
      //获取排行榜记录
      var getRankingRecord = function(gameType) {
          pomelo.request("connector.gameInfo.getRankingRecord", {gameType : "hqlMachine"}, function(data) {
              console.log(data)
            }
          );
      }
      //获取个人记录
      var getUserRecord = function(gameType) {
          pomelo.request("connector.gameInfo.getUserRecord", {gameType : "hqlMachine"}, function(data) {
              console.log(data)
            }
          );
      }
      //===================================管理员操作================================//
      //获取总库存
      var getTotalInventory = function(gameType) {
          pomelo.request("connector.admin.getTotalInventory", {gameType : gameType}, function(data) {
              console.log(data)
            }
          );
      }
      //设置总库存
      var setTotalInventory = function(gameType,level,value) {
          pomelo.request("connector.admin.setTotalInventory", {gameType : gameType,level : level,value : value}, function(data) {
              console.log(data)
            }
          );
      }
      //获取个人库存
      var getSingleInventory = function() {
          pomelo.request("connector.admin.getSingleInventory", {}, function(data) {
              console.log(data)
            }
          );
      }
      //设置个人库存
      var setSingleInventory = function(targetUid,value) {
          pomelo.request("connector.admin.setSingleInventory", {targetUid : targetUid,value : value}, function(data) {
              console.log(data)
            }
          );
      }
      //清除个人库存
      var cancelSingleInventory = function(targetUid) {
          pomelo.request("connector.admin.cancelSingleInventory", {targetUid : targetUid}, function(data) {
              console.log(data)
            }
          );
      }
      //上下分
      var changeDiamond = function(targetUid,value) {
          pomelo.request("connector.admin.changeDiamond", {targetUid : targetUid,value : value}, function(data) {
              console.log(data)
            }
          );
      }
      //获取操作记录
      var getOperatingRecord = function() {
          pomelo.request("connector.admin.getOperatingRecord", {}, function(data) {
              console.log(data)
            }
          );
      }
      //获取玩家基础信息
      var getBasicInfo = function(targetUid) {
          pomelo.request("connector.admin.getBasicInfo", {targetUid : targetUid}, function(data) {
              console.log(data)
            }
          );
      }
      var admin_getRoomList = function() {
          pomelo.request("connector.admin.getRoomList", {}, function(data) {
              console.log(data)
            }
          )
      }
      //===================================游戏操作================================//
      //开始发牌
      var sendCard = function() {
          sendData("sendCard",{power : 1})
      }
      //换牌 indexs  要换的牌的下标
      var changeCards = function() {
          sendData("changeCards",{indexs : []})
      }
      //取分
      var takeScore = function() {
          sendData("takeScore",{})
      }
      //比大小  bigFlag  true为大   false为小   比大小类型 rateType   "half"  半比  "same"  比倍  "twice"  双比
      var dicing = function() {
          sendData("dicing",{bigFlag : true})
      }
      var dicing1 = function() {
          sendData("dicing",{bigFlag : true,rateType : "half"})
      }
      var dicing2 = function() {
          sendData("dicing",{bigFlag : true,rateType : "same"})
      }
      var dicing3 = function() {
          sendData("dicing",{bigFlag : true,rateType : "twice"})
      }
      //查询房间历史记录
      var getHistory = function() {
          sendData("getHistory",{})
      }
      //获取比牌记录
      var getDicingHistory = function() {
          sendData("getDicingHistory",{})
      }
      //获取出奖记录
      var getRecordHistory = function() {
        sendData("getRecordHistory",{})
      }
      //获取当前房间信息
      var getRoomInfo = function() {
          sendData("getRoomInfo",{})
      }
      //测试牌型
      var checkCardType = function() {
        var handCards =  [
        {"num":12,"type":2,"index":2},
        {"num":12,"type":1,"index":29},
        {"num":2,"type":3,"index":7},
        {"num":6,"type":0,"index":8},
        {"num":6,"type":0,"index":52}]
        sendData("checkCardType",{handCards : handCards})
      }
      
      var queryEntry = function(uid,callback) {
        var route = 'gate.gateHandler.queryClientEntry';
        pomelo.init({
          host: host,
          port: "3910",
          log: true
        }, function(data) {
          console.log("!!!!!")
          console.log(data)
          pomelo.request(route, {
            uid: uid
          }, function(data) {
            console.log("11data !!!!")
            console.log(data)
            pomelo.disconnect();
            if(data.code === 500) {
              console.log(data)
              return;
            }
            callback(host, data.port);
          });
        });
      };
    </script>
  </head>
  <body>
    <div class="g-doc">
      <div class="g-button">
        <input id="test" type="button" value="登录" onclick="vlogin()"/>
        <input id="test" type="button" value="创建房间" onclick="newRoom()"/>
        <input id="test" type="button" value="开始发牌" onclick="sendCard()"/>
        <input id="test" type="button" value="换牌" onclick="changeCards(1)"/>
        <input id="test" type="button" value="取分" onclick="takeScore(1)"/>
        <input id="test" type="button" value="比大小" onclick="dicing()"/>
        <input id="test" type="button" value="半比" onclick="dicing1()"/>
        <input id="test" type="button" value="比倍" onclick="dicing2()"/>
        <input id="test" type="button" value="双比" onclick="dicing3()"/>
        <input id="test" type="button" value="查询房间历史记录" onclick="getHistory()"/>
        <input id="test" type="button" value="查询比大小历史记录" onclick="getDicingHistory()"/>
        <input id="test" type="button" value="查询出奖记录" onclick="getRecordHistory()"/>
        <input id="test" type="button" value="获取当前房间信息" onclick="getRoomInfo()"/>
        <input id="test" type="button" value="退出房间" onclick="userQuit()"/>
        <input id="test" type="button" value="获取大厅房间数据" onclick="getLobbyInfo()"/>
        <input id="test" type="button" value="获取排行榜记录" onclick="getRankingRecord()"/>
        <input id="test" type="button" value="获取个人记录" onclick="getUserRecord()"/>
        <input id="test" type="button" value="加入大厅房间" onclick="joinLobbyRoom()"/>
        <input id="test" type="button" value="锁定机器" onclick="lockingMaching(1)"/>
      </div>
    </div>
  </body>
</html>
